
#include <SFML/System.hpp>
#include <SFML/Graphics.hpp>
#include <iostream>

#include "BaseEntity.h"
#include "EntityManager.h"
#include "GameGlobals.h"
#include "Utility.h"
#include <time.h>

int main()
{
	srand(time(0));
    //Create the main rendering window
	float Width,Height;
	Width = 1024;
	Height = 768;
    sf::RenderWindow App(sf::VideoMode(Width, Height, 32), "SFML Graphics");
    
	App.SetFramerateLimit(100);

	sf::View MainView;

	EntityManager::Instance()->pRender = &App;
	EntityManager::Instance()->Init();
    //Start game loop
	GameGlobals::Instance()->InFocus = true;
    while (App.IsOpened())
    {
        //Process events
        sf::Event Event;
        while (App.PollEvent(Event))
        {
            //Close window : exit
            if (Event.Type == sf::Event::Closed)
                App.Close();
			if (Event.Type == sf::Event::LostFocus)
				GameGlobals::Instance()->InFocus = false;
			if (Event.Type == sf::Event::GainedFocus)
				GameGlobals::Instance()->InFocus = true;
			if (Event.Type == sf::Event::KeyPressed)
				EntityManager::Instance()->GameRules->OnKeyPressed(Event.Key.Code, App);
			//if (Event.Type == sf::Event::Resized)
        }

		App.Clear(sf::Color::White);

		EntityManager::Instance()->Tick();

        //Display window contents on screen
        App.Display();
    }

    return EXIT_SUCCESS;
}